package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.clock.ClockImplementation;
import emulator.hardware.memory.MemoryBlock;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.commands.RTS;
import emulator.hardware.nmos6502.operands.NoOperand;

public class RTSTest {

	@Test
	public void testExecute() throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MemoryBlock memory = new MemoryBlock(65536);
		ClockImplementation clock = new ClockImplementation();
		cpu.attach(memory, clock);
		cpu.setPC(0xFEDC);
		cpu.setSP(new HwByte(0xFD));
		memory.write(0x1FF, 0x1A);
		memory.write(0x1FE, 0x2A);

		RTS rts = new RTS();
		rts.execute(cpu, new NoOperand());
		assertEquals(0xFF, cpu.getSP().getNumber());
		assertEquals(0x1A2B, cpu.getPC());
	}

}
